<?php
/* @var $this PhanquaController */
/* @var $model Phanqua */
/* @var $form CActiveForm */
?>

<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'phanqua-_phanqua-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // See class documentation of CActiveForm for details on this,
        // you need to use the performAjaxValidation()-method described there.
        'enableAjaxValidation' => false,
    ));
    ?>



        <?php echo $form->errorSummary($model); ?>

    <div class="form_left">
        <?php echo $form->labelEx($model, 'programid'); ?>
    </div>
    <div class="form_right">
        <?php
        $program = Program::model()->findAll('flag=1');

        $list = CHtml::listData($program, 'gid', 'title');
        echo $form->dropDownList($model, 'programid', $list);
        // echo $form->textField($model,'programid'); 
        ?>
        <?php echo $form->error($model, 'programid'); ?>
    </div>
    <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'name'); ?>
    </div>
    <div class="form_right">
<?php echo $form->textField($model, 'name'); ?>
        <?php echo $form->error($model, 'name'); ?>
    </div>
 <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'numberpeople'); ?>
    </div>
    <div class="form_right">
<?php echo $form->textField($model, 'numberpeople'); ?>
        <?php echo $form->error($model, 'numberpeople'); ?>
    </div>
 <div class="clear"></div>
    <div class="form_left">
        <?php echo $form->labelEx($model, 'flag'); ?>
    </div>
    <div class="form_right">
<?php echo $form->dropDownList($model, 'flag',array('0' => 'Ẩn', '1' => 'Hiễn thị')); ?>
<?php echo $form->error($model, 'flag'); ?>
    </div>
 <div class="clear"></div>
    <div class="form_left">.</div>
    <div class="form_right">

    <?php echo CHtml::submitButton('Cập nhật'); ?>
    </div>
 <div class="clear"></div>
<?php $this->endWidget(); ?>

</div><!-- form -->

<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/media/css/demo_table_jui.css" />
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css" />
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        oTable = $('#example').dataTable({
            "bJQueryUI": true,
            "sPaginationType": "full_numbers"
        });
    });
</script>
<?php 


  $sql = 'SELECT t1.id,t1.name,t1.numberpeople,t1.flag,t2.title FROM `phanqua` AS t1 INNER JOIN `program` AS t2 on t1.programid =t2.gid where t1.flag<2 and t2.flag=1';
        $dbCommand = Yii::app()->db->createCommand($sql);
        $results = $dbCommand->queryAll();
              
if (!empty($results)) { ?>
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
        <thead>
            <tr>
                <th>Chương trình</th>
                <th>Phần quà</th>
                <th>Số người tham gia</th>
                <th>Xóa</th>
            </tr>
        </thead>
        <tbody>
            <?php
            //include 'encode_decode.php';

            Yii::import('application.controllers.home.encode_decode');
            $md = new encode_decode();
            if (!empty($results)) {
                foreach ($results as $item) {
                    $ma = $md->encrypt($item['id']);
                    ?>
                    <tr class="gradeA">
                        <td>

                            <?php echo '<a style="text-decoration: none" href="' . Yii::app()->request->baseUrl . '/xem-phanqua/' . $ma . '">' . $item['title'] . '</a>' ?>
                        </td>

                        <td class="center"><?php 
                       

                        echo $item['name']; 
                        ?></td>
                        <td class="center">
                            <?php
                           echo $item['numberpeople'];
                            ?>
                        </td>
                        <td class="center">
                            <?php echo '<a style="text-decoration: none;color: red" href="' . Yii::app()->request->baseUrl . '/xoa-phanqua/' . $ma . '">' . 'Xóa</a>' ?>
              
                        </td>
                    </tr>
                    <?php
                }
            }
            ?>
        </tbody>
    </table>
    <?php
} else {
    echo 'Bạn chưa cài đặt phần quà nào!';
}

